
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

class Solution
{
public:
    bool CheckPermutation1(string s1, string s2)
    {
        if (s1.size() != s2.size())
            return false;

        sort(s1.begin(), s1.end());
        sort(s2.begin(), s2.end());

        return s1 == s2;
    }

    bool CheckPermutation2(string s1, string s2)
    {
        if (s1.size() != s2.size())
            return false;

        int cnt[26] = { 0 };

        for (const auto& e : s1)
        {
            ++cnt[e - 'a'];
        }
        for (const auto& e : s2)
        {
            --cnt[e - 'a'];
            if (cnt[e - 'a'] < 0)
                return false;
        }

        return true;
    }

    int timeRequiredToBuy1(vector<int>& tickets, int k)
    {
        int time = 0;
        int n = tickets.size();
        queue<pair<int, int>> q;

        for (int i = 0; i < n; ++i)
        {
            q.push({ tickets[i], i });
        }

        while (true)
        {
            if (0 == --q.front().first)
            {
                if (k == q.front().second)
                {
                    ++time;
                    break;
                }
                q.pop();
            }
            else
            {
                auto front = q.front();
                q.pop();
                q.push(front);
            }
            ++time;
        }

        return time;
    }

    int timeRequiredToBuy2(vector<int>& tickets, int k)
    {
        int res = 0;

        for (int i = 0, n = tickets.size(); i < n; ++i)
        {
            res += min(tickets[i], tickets[k] - (i > k ? 1 : 0));
        }

        return res;
    }
};

int main()
{


	return 0;
}